#include "UnknownTypeErr.h"

#include <stdarg.h>
#include <string.h>
#include <fan-llvm/core/Core.h>
#include "Str.h"
#include "Type.h"


Type* UnknownTypeErr_classType = NULL;
VTable* UnknownTypeErr_classVTable = NULL;


/**********************************************
 *
 * Methods and fields
 *
 **********************************************/


/* Void make(Str msg, Err? cause) */
void UnknownTypeErr_make_0(UnknownTypeErr* self)
{
  UnknownTypeErr_make(self, Str_defVal(), NULL);
}


/* Void make(Str msg, Err? cause) */
void UnknownTypeErr_make_1(UnknownTypeErr* self, Str* msg)
{
  UnknownTypeErr_make(self, msg, NULL);
}


/* Void make(Str msg, Err? cause) */
void UnknownTypeErr_make(UnknownTypeErr* self, Str* msg, Err* cause)
{
  Err_make((Err*)self, msg, cause);
}


/**********************************************
 *
 * Extra methods
 *
 **********************************************/


/* Create a new UnknownTypeErr instance and initialize it with UnknownTypeErr_make() */
UnknownTypeErr* UnknownTypeErr_new(Str* msg, Err* cause)
{
  UnknownTypeErr* err = (UnknownTypeErr*)Obj_allocate(sizeof(UnknownTypeErr), UnknownTypeErr_classVTable);
  UnknownTypeErr_make(err, msg, cause);
  return err;
}


/* Create a new UnknownTypeErr instance and initialize it with the message given by the specified format.
 * 'msgFormat' uses the same format as Str_newWithFormat() */
UnknownTypeErr* UnknownTypeErr_newWithFormattedMsg(const char* msgFormat, ...)
{
  va_list args;
  va_start(args, msgFormat);
  Str* msg = Str_newWithFormatValist(msgFormat, args);
  va_end(args);
  return UnknownTypeErr_new(msg, NULL);
}


/**********************************************
 *
 * Type-system functions
 *
 **********************************************/


Type* UnknownTypeErr_initType(void)
{
  if (UnknownTypeErr_classType == NULL)
  {
    Type* baseType = Err_initType();
    VTable* vtable = UnknownTypeErr_initVTable();
    Type* type = Type_new("UnknownTypeErr", baseType, vtable, sizeof(UnknownTypeErr), sizeof(UnknownTypeErrVTable));
    Type_registerCtorImplementation(type, "make", UnknownTypeErr_make_0, 0);
    Type_registerCtorImplementation(type, "make", UnknownTypeErr_make_1, 1);
    Type_registerCtorImplementation(type, "make", UnknownTypeErr_make, 2);
    UnknownTypeErr_classType = type;
    UnknownTypeErr_initStatic();
  }
  return UnknownTypeErr_classType;
}


VTable* UnknownTypeErr_initVTable(void)
{
  if (UnknownTypeErr_classVTable == NULL)
  {
    VTable* vtable = memoryAlloc(sizeof(UnknownTypeErrVTable));
    memcpy(vtable, Err_initVTable(), sizeof(ErrVTable));
    UnknownTypeErr_classVTable = vtable;
  }
  return UnknownTypeErr_classVTable;
}


void UnknownTypeErr_initStatic(void)
{
}
